import { MemoryManager } from "GameLoop/DecisionMaking/MemoryManager";
import { ABaseEntity } from "GameLoop/WorldState/EntityManager/Entitys/BaseEntity";
import { AllEntityTypes, ExucuteType, IEntity } from "GameLoop/WorldState/EntityManager/Entitys/Entity.interface";

 

 
/**
 * 房间位置拓展
 */
export default class EntityExtension extends PowerCreep implements IEntity<PowerCreepMemory & INoMemory>
{
    public entityType(): ExucuteType {
        return "PowerCreep"
    }
    initAttributes():void
    {
        MemoryManager.allocHeap(this.GUID());
    }
    public getEntityByID<T extends ABaseEntity<INoMemory>>(id: string): T 
    {
        return global.entityDB.getEntityByID<T>(id);         
    }
    public  getEntity<T extends keyof AllEntityTypes>(type: T, region: string=this.memory.OwnerRoom): AllEntityTypes[T] {
        return global.entityDB.getEntity(type,region);    
    }
    public getEntitys<T extends keyof AllEntityTypes>(type: T, region: string=this.memory.OwnerRoom): AllEntityTypes[T][] {
        return global.entityDB.getEntitys(type,region);    
    }
    removeEntityByID(id: string): boolean {
        return global.entityDB.removeEntityByID(id);
    }
    public getNodeMemory(): PowerCreepMemory   {
        return this.memory 
    }
    public GUID()
    {
        return this.name
    }

    /**
     * 绑定的房间
     * @returns 
     */
    public  ownerRoom():Room
    {
        return Game.rooms[this.memory.OwnerRoom]
    }

    public log(type:LogType,...arg:[]):void
    {
        global.Log.Text(this.GUID(),arg.join("\t"),type);
    }
    public crossLevel():number
    {
        if(this.memory.taskid  )
        {
            return this.memory.crossLevel;
        }
        return 0
    }
    public getNodeHeap<T extends any=CreepHeap>(): T{
        
        return MemoryManager.getHeap(this.GUID());
     }
 }